using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region SalesTeamInfo

	/// <summary>
	/// SalesTeamInfo object for NHibernate mapped table 'SalesTeamInfo'.
	/// </summary>
	[Serializable]
	public class SalesTeamInfo : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _hostNameCN;
		protected string _hostNameEN;
		protected string _officeTel;
		protected string _officeFax;
		protected string _email;
		protected string _salesBusinessUnit;
		protected string _region;
		protected Application _application;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public SalesTeamInfo() { }

		public SalesTeamInfo( string hostNameCN, string hostNameEN, string officeTel, string officeFax, string email, string salesBusinessUnit, string region, Application application )
		{
			this._hostNameCN = hostNameCN;
			this._hostNameEN = hostNameEN;
			this._officeTel = officeTel;
			this._officeFax = officeFax;
			this._email = email;
			this._salesBusinessUnit = salesBusinessUnit;
			this._region = region;
			this._application = application;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string HostNameCN
		{
			get { return _hostNameCN; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for HostNameCN", value, value.ToString());
				_hostNameCN = value;
			}
		}

		public string HostNameEN
		{
			get { return _hostNameEN; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for HostNameEN", value, value.ToString());
				_hostNameEN = value;
			}
		}

		public string OfficeTel
		{
			get { return _officeTel; }
			set
			{
				if ( value != null && value.Length > 50)
					value = value.Substring(0, 50 );
				_officeTel = value;
			}
		}

		public string OfficeFax
		{
			get { return _officeFax; }
			set
			{
				if ( value != null && value.Length > 50)
					value = value.Substring(0, 50 );
				_officeFax = value;
			}
		}

		public string Email
		{
			get { return _email; }
			set
			{
				if ( value != null && value.Length > 50)
					value = value.Substring(0, 50 );
				_email = value;
			}
		}

		public string SalesBusinessUnit
		{
			get { return _salesBusinessUnit; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for SalesBusinessUnit", value, value.ToString());
				_salesBusinessUnit = value;
			}
		}

		public string Region
		{
			get { return _region; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Region", value, value.ToString());
				_region = value;
			}
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is SalesTeamInfo))
				throw new InvalidCastException("This object is not of type SalesTeamInfo");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((SalesTeamInfo)obj).Id);
					break;
				case "HostNameCN":
						relativeValue = ( this.HostNameCN != null ) ? this.HostNameCN.CompareTo(((SalesTeamInfo)obj).HostNameCN) : -1;
					break;
				case "HostNameEN":
						relativeValue = ( this.HostNameEN != null ) ? this.HostNameEN.CompareTo(((SalesTeamInfo)obj).HostNameEN) : -1;
					break;
				case "OfficeTel":
						relativeValue = ( this.OfficeTel != null ) ? this.OfficeTel.CompareTo(((SalesTeamInfo)obj).OfficeTel) : -1;
					break;
				case "OfficeFax":
						relativeValue = ( this.OfficeFax != null ) ? this.OfficeFax.CompareTo(((SalesTeamInfo)obj).OfficeFax) : -1;
					break;
				case "Email":
						relativeValue = ( this.Email != null ) ? this.Email.CompareTo(((SalesTeamInfo)obj).Email) : -1;
					break;
				case "SalesBusinessUnit":
						relativeValue = ( this.SalesBusinessUnit != null ) ? this.SalesBusinessUnit.CompareTo(((SalesTeamInfo)obj).SalesBusinessUnit) : -1;
					break;
				case "Region":
						relativeValue = ( this.Region != null ) ? this.Region.CompareTo(((SalesTeamInfo)obj).Region) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (SalesTeamInfo.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
